
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rotempco.Core.ORM.ADAL;
using System.Data.SqlClient;
using Rotempco.BaseClass.Objects.EntityObjects;
using Rotempco.Core.ORM.Objects;
using Rotempco.Core.ORM.Objects.Enums;
using Rotempco.Core.ORM.Logic;
using Rotempco.Core.Logic;




namespace Rotempco.BaseClass.DAL
{
    public partial class LoginHistoryData : ADAL<LoginHistory, long>
    {
	    #region [ ADATA Implementation ]

        protected override string GetTableName()
        {
            return "LoginHistory";
        }

        protected override Pair<string, string> GetIdentity()
        {
            return new Pair<string, string>("LoginHistoryId", SymbolExtensions.GetPropertyName((LoginHistory d) => d.LoginHistoryId));
        }

        protected override List<ORMParameter> GetORMMapping()
        {
            List<ORMParameter> mapping = new List<ORMParameter>();
		
			mapping.Add(new ORMParameter("LoginUserId", SymbolExtensions.GetPropertyPair((LoginHistory d) => d.LoginUserId)));
			mapping.Add(new ORMParameter("LoginName", SymbolExtensions.GetPropertyPair((LoginHistory d) => d.LoginName)));
			mapping.Add(new ORMParameter("Success", SymbolExtensions.GetPropertyPair((LoginHistory d) => d.Success)));
			mapping.Add(new ORMParameter("Timestamp", SymbolExtensions.GetPropertyPair((LoginHistory d) => d.Timestamp)));
			mapping.Add(new ORMParameter("SuspendedUntil", SymbolExtensions.GetPropertyPair((LoginHistory d) => d.SuspendedUntil)));

            return mapping;
        }

        #endregion

        #region [ GetBy ]

        public LoginHistory GetSingle(bool getDeleted = false, long? loginHistoryId = null, long? loginUserId = null, string loginName = null, bool? success = null, DateTime? timestamp = null, DateTime? suspendedUntil = null , bool? loginUserIdIsNull = null, bool? suspendedUntilIsNull = null)
        {
            List<PropertyPair> parameterList = GetByParameterList(loginHistoryId: loginHistoryId, loginUserId: loginUserId, loginName: loginName, success: success, timestamp: timestamp, suspendedUntil: suspendedUntil);
            List<NullablePair> nullablePairList = GetNullablePairList(loginUserIdIsNull: loginUserIdIsNull, suspendedUntilIsNull: suspendedUntilIsNull);
            return GetBy(parameterList, getDeleted, nullablePairList: nullablePairList).SingleOrDefault();
        }

        public List<LoginHistory> GetList(bool getDeleted = false, long? getFirstEntries = null, long? getLastEntries = null, long? loginHistoryId = null, long? loginUserId = null, string loginName = null, bool? success = null, DateTime? timestamp = null, DateTime? suspendedUntil = null , bool? loginUserIdIsNull = null, bool? suspendedUntilIsNull = null)
        {
            List<PropertyPair> parameterList = GetByParameterList(loginHistoryId: loginHistoryId, loginUserId: loginUserId, loginName: loginName, success: success, timestamp: timestamp, suspendedUntil: suspendedUntil);
            List<NullablePair> nullablePairList = GetNullablePairList(loginUserIdIsNull: loginUserIdIsNull, suspendedUntilIsNull: suspendedUntilIsNull);
            return GetBy(parameterList, getDeleted, getFirstEntries, getLastEntries, nullablePairList: nullablePairList);
        }

        #endregion

        #region [ Private ]

        private List<PropertyPair> GetByParameterList(long? loginHistoryId = null, long? loginUserId = null, string loginName = null, bool? success = null, DateTime? timestamp = null, DateTime? suspendedUntil = null)
        {
            List<PropertyPair> mapping = new List<PropertyPair>();

			mapping.Add(new PropertyPair(loginHistoryId, SymbolExtensions.GetPropertyPair((LoginHistory d) => d.LoginHistoryId)));
			mapping.Add(new PropertyPair(loginUserId, SymbolExtensions.GetPropertyPair((LoginHistory d) => d.LoginUserId)));
			mapping.Add(new PropertyPair(loginName, SymbolExtensions.GetPropertyPair((LoginHistory d) => d.LoginName)));
			mapping.Add(new PropertyPair(success, SymbolExtensions.GetPropertyPair((LoginHistory d) => d.Success)));
			mapping.Add(new PropertyPair(timestamp, SymbolExtensions.GetPropertyPair((LoginHistory d) => d.Timestamp)));
			mapping.Add(new PropertyPair(suspendedUntil, SymbolExtensions.GetPropertyPair((LoginHistory d) => d.SuspendedUntil)));

            return mapping;
        }

        private List<NullablePair> GetNullablePairList(bool? loginUserIdIsNull = null, bool? suspendedUntilIsNull = null)
        {
            List<NullablePair> nullablePairList = new List<NullablePair>();

			if (loginUserIdIsNull.HasValue)
                nullablePairList.Add(new NullablePair(PropertyLogic.GetPropertyName((LoginHistory c) => c.LoginUserId),loginUserIdIsNull.Value));
			if (suspendedUntilIsNull.HasValue)
                nullablePairList.Add(new NullablePair(PropertyLogic.GetPropertyName((LoginHistory c) => c.SuspendedUntil),suspendedUntilIsNull.Value));


            if (nullablePairList.Count <= 0)
                return null;

            return nullablePairList;
        }

        #endregion

	}
}

